package ${table.excelImportClassPackage};
import ${table.entityClassPackage}.${table.beanName};
import ${table.serviceClassPackage}.${table.beanName}Service;


import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.excel.context.AnalysisContext;


import java.util.List;

/**
* @author：${table.author}
* @since：${table.date}
* @remark：${table.comment}
*/
@Slf4j
public class ${table.beanName}Listener implements ReadListener<${table.beanName}> {
    /**
    * 每隔100条存储数据库,然后清理list,方便内存回收
    */
    private static final int BATCH_COUNT = 100;
    /**
    * 缓存的数据
    */
    private List<${table.beanName}> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
    private ${table.beanName}Service ${table.somallbeanName}ServiceImpl;
    public ${table.beanName}Listener (${table.beanName}Service ${table.somallbeanName}ServiceImpl) {
        this.${table.somallbeanName}ServiceImpl = ${table.somallbeanName}ServiceImpl;
    }
    @Override
    public void invoke(${table.beanName} ${table.somallbeanName}, AnalysisContext context) {
    log.info("解析到一条数据:{}", ${table.somallbeanName});
    cachedDataList.add(${table.somallbeanName});
    // 达到BATCH_COUNT了，需要去存储一次数据库，防止数据几万条数据在内存，容易OOM
    if (cachedDataList.size() >= BATCH_COUNT) {
        ${table.somallbeanName}ServiceImpl.saveBatch(cachedDataList);
        // 存储完成清理 list
        cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
        }
    }
    /**
    * 所有数据解析完成了 都会来调用
    *
    * @param context
    */
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        // 这里也要保存数据，确保最后遗留的数据也存储到数据库
        ${table.somallbeanName}ServiceImpl.saveBatch(cachedDataList);
        log.info("所有数据解析完成！");
    }
}